package com.farm.resume.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.farm.core.page.OperateType;
import com.farm.core.page.RequestMode;
import com.farm.core.page.ViewMode;
import com.farm.core.sql.query.DataQuery;
import com.farm.core.sql.result.DataResult;
import com.farm.resume.domain.Resumeintension;
import com.farm.resume.service.ResumeintensionServiceInter;
import com.farm.web.WebUtils;
import com.farm.web.easyui.EasyUiUtils;

@RequestMapping({ "/resumeintension" })
@Controller
public class ResumeintensionController extends WebUtils {
	private static final Logger log = Logger.getLogger(ResumeintensionController.class);
	@Resource
	ResumeintensionServiceInter resumeIntensionServiceImpl;

	public ResumeintensionServiceInter getResumeintensionServiceImpl() {
		return this.resumeIntensionServiceImpl;
	}

	public void setResumeintensionServiceImpl(ResumeintensionServiceInter resumeIntensionServiceImpl) {
		this.resumeIntensionServiceImpl = resumeIntensionServiceImpl;
	}

	@RequestMapping({ "/query" })
	@ResponseBody
	public Map<String, Object> queryall(DataQuery query, HttpServletRequest request) {
		try {
			query = EasyUiUtils.formatGridQuery(request, query);
			DataResult result = this.resumeIntensionServiceImpl.createResumeintensionSimpleQuery(query).search();
			return ViewMode.getInstance().putAttrs(EasyUiUtils.formatGridData(result)).returnObjMode();
		} catch (Exception e) {
			log.error(e.getMessage());
			return ViewMode.getInstance().setError(e.getMessage()).returnObjMode();
		}
	}

	@RequestMapping({ "/edit" })
	@ResponseBody
	public Map<String, Object> editSubmit(Resumeintension entity, HttpSession session) {
		try {
			entity = this.resumeIntensionServiceImpl.editResumeintensionEntity(entity, getCurrentUser(session));
			return ViewMode.getInstance().setOperate(OperateType.UPDATE).putAttr("entity", entity).returnObjMode();
		} catch (Exception e) {
			log.error(e.getMessage());
			return ViewMode.getInstance().setOperate(OperateType.UPDATE).setError(e.getMessage()).returnObjMode();
		}
	}

	@RequestMapping({ "/add" })
	@ResponseBody
	public Map<String, Object> addSubmit(Resumeintension entity, HttpSession session) {
		try {
			entity = this.resumeIntensionServiceImpl.insertResumeintensionEntity(entity, getCurrentUser(session));
			return ViewMode.getInstance().setOperate(OperateType.ADD).putAttr("entity", entity).returnObjMode();
		} catch (Exception e) {
			log.error(e.getMessage());
			return ViewMode.getInstance().setOperate(OperateType.ADD).setError(e.getMessage()).returnObjMode();
		}
	}

	@RequestMapping({ "/del" })
	@ResponseBody
	public Map<String, Object> delSubmit(String ids, HttpSession session) {
		try {
			for (String id : parseIds(ids)) {
				this.resumeIntensionServiceImpl.deleteResumeintensionEntity(id, getCurrentUser(session));
			}
			return ViewMode.getInstance().returnObjMode();
		} catch (Exception e) {
			log.error(e.getMessage());
			return ViewMode.getInstance().setError(e.getMessage()).returnObjMode();
		}
	}

	@RequestMapping({ "/list" })
	public ModelAndView index(HttpSession session) {
		return ViewMode.getInstance().returnModelAndView("resume/ResumeintensionResult");
	}

	@RequestMapping({ "/form" })
	public ModelAndView view(RequestMode pageset, String ids) {
		try {
			switch (pageset.getOperateType()) {
			case 0:
				return

				ViewMode.getInstance().putAttr("pageset", pageset)
						.putAttr("entity", this.resumeIntensionServiceImpl.getResumeintensionEntity(ids))
						.returnModelAndView("resume/ResumeintensionForm");

			case 1:
				return ViewMode.getInstance().putAttr("pageset", pageset)
						.returnModelAndView("resume/ResumeintensionForm");

			case 2:
				return

				ViewMode.getInstance().putAttr("pageset", pageset)
						.putAttr("entity", this.resumeIntensionServiceImpl.getResumeintensionEntity(ids))
						.returnModelAndView("resume/ResumeintensionForm");
			}

			return ViewMode.getInstance().returnModelAndView("resume/ResumeintensionForm");
		} catch (Exception e) {
			return ViewMode.getInstance().setError(e + e.getMessage()).returnModelAndView("resume/ResumeintensionForm");
		}
	}
}
